// pages/myPost/myPost.js

const db = wx.cloud.database()
// const message = db.collection('association')

Page({

    /**
     * 页面的初始数据
     */
    data: {
      message: [],
      list_1: [],
      list_2: [],
      list_3: [],
      list_4: [],
      list_5: [],
      list_6: [],
      openID: ''
    },
    
    
    /* 删除发帖 */
    deletePost: function(e) {
      wx.showModal({
        title: '提示',
        content: '确定要删除吗QWQ',
        success: function (res) {
          if (res.confirm) {
            console.log('确定删除')
            wx.showModal({
                title: '提示',
                content: '删除成功',
              })
          } else {
            console.log('取消删除')
          }
        }
      })
    },

    onLoad(options) {
        this.setData({
            openID: getApp().globalData.usrOpenID
        })

        db.collection('association').where({
              _openid: this.data.openID
        }).get()
        .then(res => {
        //动态将查询结果存入list数组
            this.setData({
                list_1: res.data
            })
            console.log(this.data.list_1)
        })
        .catch(res => {
            console.log("查询失败")
        })

        db.collection('lostandfound').where({
            _openid: this.data.openID
        }).get()
        .then(res => {
        //动态将查询结果存入list数组
            this.setData({
                list_2: res.data
            })
            console.log(this.data.list_2)
        })
        .catch(res => {
            console.log("查询失败")
        })

        db.collection('red').where({
            _openid: this.data.openID
        }).get()
         .then(res => {
        //动态将查询结果存入list数组
            this.setData({
                list_3: res.data
            })
            console.log(this.data.list_3)
        })
        .catch(res => {
            console.log("查询失败")
        })

        db.collection('black').where({
            _openid: this.data.openID
        }).get()
        .then(res => {
        //动态将查询结果存入list数组
            this.setData({
                list_4: res.data
            })
            console.log(this.data.list_4)
        })
        .catch(res => {
            console.log("查询失败")
        })

        db.collection('secondhand').where({
            _openid: this.data.openID
        }).get()
        .then(res => {
        //动态将查询结果存入list数组
            this.setData({
                list_5: res.data
            })
            console.log(this.data.list_5)
        })
        .catch(res => {
            console.log("查询失败")
        })

        db.collection('Assistant_DataSheet').where({
            _openid: this.data.openID
        }).get()
        .then(res => {
        //动态将查询结果存入list数组
            this.setData({
                list_6: res.data
            })
            console.log(this.data.list_6)
        })
        .catch(res => {
            console.log("查询失败")
        })

    },
})